﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Vit.Mvc.Providers
{
    public class DefaultHtmlRenderProvider : IHtmlRenderProvider
    {
        #region IHtmlRenderProvider Members

        public MvcHtmlString Render(string controlId, ControlType controlType, bool isRange, string format, object val, string controlAttributes, string controlStyles)
        {
            StringBuilder sb = new StringBuilder();
            if(!string.IsNullOrEmpty(controlAttributes))
                controlAttributes = string.Concat(" ", controlAttributes);
            if(!string.IsNullOrEmpty(controlStyles))
                controlStyles = string.Format(" style=\"{0}\"", controlStyles);

            switch (controlType)
            {
                case ControlType.SingleLineLabel:
                    sb.AppendFormat(@"<span{0}{1}>{2}</span>",
                        controlAttributes, controlStyles, string.Format(format, val));
                    break;
                case ControlType.TextBox:
                    sb.AppendFormat(@"<input id=""{0}"" type='textbox'{1}{2} value='{3}'></input>",
                        controlId,
                        controlAttributes, controlStyles, string.Format(format, val));
                    break;
                case ControlType.HiddenText:
                    sb.AppendFormat(@"<input id=""{0}"" type='hidden' value='{1}'></input>",
                        controlId, string.Format(format, val));
                    break;
            }
            return MvcHtmlString.Create(sb.ToString());
        }

        #endregion
    }
}
